<template>
  <div class="all-content-echart">
    <div class="left-echart">
      <el-card>
        <p>累计项目授权统计（{{year}}年）</p>
        <div id="postProd" ref="postProd"></div>
      </el-card>
    </div>
    <div class="right-text">
      <el-card>
        <div class="top" v-if="dataMsg.projInfo">
          <p>累计项目总数</p>
          <span class="blue">{{dataMsg.projInfo.length}}</span>
        </div>
        <div class="bottom">
          <p>累计项目授权总数</p>
          <span class="blue">{{dataMsg.sumProjAuthNum}}</span>
          <p>今日项目授权总数</p>
          <span class="black">{{dataMsg.dayProjCount}}</span>
        </div>
      </el-card>
    </div>
  </div>
</template>
<script>
import echarts from 'echarts'
import LoginSrv from "../api/login.service";

export default {
  data () {
    return {
      year: new Date().getFullYear(),
      dataMsg: []
    }
  },
  created () {
  },
  mounted () {
    this.initData()
  },
  methods: {
    initData () {
      LoginSrv.getSumProjAuthCount().then(res => {
        if (res.code == 10200) {
          this.dataMsg = res.data
          let maxA = Math.max(...res.data.projAuthNum)
          console.log(maxA);
          this.dataMsg.projAuthNum.push(maxA)
          this.initPostAll()
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    initPostAll () {
      console.log(this.dataMsg.projInfo);
      let line = this.$echarts.init(this.$refs.postProd);
      let option = {
        // color: ['#3398DB'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: ''
          }
        },
        xAxis: [
          {
            type: 'category',
            data: this.dataMsg.projInfo,
            boundaryGap: true,
            axisTick: {
              alignWithLabel: true
            },
            axisLabel: {
              interval: 0,
              rotate:45,
              formatter: function(value){
                return value.length>3?value.substring(0,3)+'...':value;
              },
              textStyle: {
                color: '#333',
                fontSize: 12
              }
            },
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '授权数/个',
            axisLabel: { // 坐标轴字体颜色大小
              textStyle: {
                color: '#333',
                fontSize: 12
              }
            },
          }
        ],
        series: [
          {
            name: '授权个数',
            type: 'bar',
            barWidth:'16',
            data: this.dataMsg.projAuthNum,
            label: {
              normal: {
                show:true,
                position: 'top'
              }
            },
            itemStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(
                  0,0,0,1,
                    [
                      {
                        offset: 0,
                        color: '#22A5E2'
                      },
                      {
                        offset: 0.8,
                        color: '#47B7EB'
                      },
                      {
                        offset: 1,
                        color: '#70CBF6'
                      }
                    ]
                ),
                label: {
                  show: true,
                  position: 'top',
                  textStyle: {
                    color: '#22A5E2'
                  }
                }
              }
            },
            // 鼠标事件
            emphasis: {
              itemStyle: {
                color: new this.$echarts.graphic.LinearGradient(
                  0,0,0,1,
                  [
                    {offset: 0,color: '#2378f7'},
                    {offset: 0.7,color: '#2378f7'},
                    {offset: 1,color: '#83bff6'}
                  ]
                )
              }
            },
            markLine: {
              data: [{ type: "average", name: "平均值" }],
              lineStyle: {
                color: '#22A5E2' // 线颜色
              },
            },
          }
        ]
      };
      line.setOption(option);
    }
  }
}
</script>
<style lang="less" scoped>
.all-content-echart {
  display: flex;
  margin-top: 16px;
  .left-echart {
    width: 80%;
    height: 440px;
    margin-right: 16px;
    p {
      font-size: 16px;
      font-weight: bold;
      color: #333;
      padding-bottom: 16px;
      border-bottom: 1px solid #CACDD2;
    }
  }
  .right-text {
    width: 20%;
    height: 440px;
    text-align: center;
    p {
      font-size: 14px;
      color: #666;
    }
    .bottom {
      border-top: 1px solid #CACDD2;
      padding-top: 30px;
    }
    .blue {
      display: inline-block;
      font-size: 24px;
      color: #22A5E2;
      font-weight: bold;
      padding: 16px 0 28px;
    }
    .black {
      display: inline-block;
      font-size: 24px;
      color: #333;
      font-weight: bold;
      padding-top: 16px;
    }
  }
  .el-card {
    width: 100%;
    height: 100%;
  }
  #postProd {
    width: 100%;
    height: 100%;
  }
}
</style>
<style>

.all-content-echart .el-card__body {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
</style>
